package repaso_bolita;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;

public class Bolita {
	public int iDiametro = 30;

	public int iPosX, iPosY, iVelX, iVelY;
	private ClaPanelBolita PBmesaJuego;

	public Bolita(ClaPanelBolita juego) {
		iPosX = iPosY = 12;
		iVelX = 0;
		iVelY = 0;
		this.PBmesaJuego = juego;
	}
	
	

	public Bolita(int iVelX, int iVelY, ClaPanelBolita pBmesaJuego) {
		super();
		this.iVelX = iVelX;
		this.iVelY = iVelY;
		this.PBmesaJuego = pBmesaJuego;
	}



	void moviminto() {
		if ((iPosX + iVelX < 0) || (iPosX + iVelX > PBmesaJuego.getWidth() - iDiametro))
			iVelX = -iVelX;

		else if ((iPosY + iVelY < 0) ||(iPosY + iVelY > PBmesaJuego.getHeight() - iDiametro))
			iVelY = -iVelY;
		
		
		

		iPosX = iPosX + iVelX;
		iPosY = iPosY + iVelY;
	}


	public void paint(Graphics2D g, Color color) {
		g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
				RenderingHints.VALUE_ANTIALIAS_ON);
		g.setColor(color);
		g.fillOval(iPosX, iPosY, iDiametro, iDiametro);
	}

	public Rectangle getRectBolita() {
		return new Rectangle(iPosX, iPosY, iDiametro, iDiametro);
	}
	
	

	
	/**
	 * @return the iDiametro
	 */
	public int getiDiametro() {
		return iDiametro;
	}



	/**
	 * @param iDiametro the iDiametro to set
	 */
	public void setiDiametro(int iDiametro) {
		this.iDiametro = iDiametro;
	}



	public void keyPressed(KeyEvent e) {
		switch (e.getKeyCode()) {
		case KeyEvent.VK_L:
			iVelX++;
			break;
		case KeyEvent.VK_J:
			iVelX--;
			break;
		case KeyEvent.VK_I:
			iVelY--;
			break;
		case KeyEvent.VK_M:
			iVelY++;
			break;
		case KeyEvent.VK_K:
			iVelX = iVelY = 0;
			break;
		}
	}
	
	/*
	public void mouseClicked(MouseEvent e) {

		int x, y;
		x = e.getX();
		y = e.getY();
			if(getRectBolita().intersection(new Rectangle(x, y, 2*iDiametro, 2*iDiametro)) != null){
				iDiametro += 10;
		}
	}*/
	
	public void redimensionar(){
		iDiametro +=10;
	}
	
}